package com.kharthick.pwGame.map;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.MediaTracker;
import java.util.Vector;

import com.kharthick.pwGame.sprites.Sprite;
import com.kharthick.pwGame.sprites.SpriteFactory;

public abstract class Tile {
	public final int TILE_ATTACK_BONUS;
	public final int TILE_DEFENSE_BONUS;
	public final int TILE_SIZE;
	
	private final Vector<Integer> position;
	private final Sprite sprite;
	
	private boolean mouseOver = false;
	private boolean rightClicked = false;
	private boolean leftClicked = false;
	
	public Tile(
			String filename,
			MediaTracker tracker,
			int tileSize,
			Vector<Integer> pos,
			int tileAttackBonus,
			int tileDefenseBonus) {

		TILE_SIZE = tileSize;
		TILE_ATTACK_BONUS = tileAttackBonus;
		TILE_DEFENSE_BONUS = tileDefenseBonus;
		sprite = SpriteFactory.getSprite(filename, tracker);
		position = pos;
	}
	
	public void draw(Graphics buf) {
		// sample lines... these get draw for some reason on the first frame
		int x = TILE_SIZE*position.get(0);
		int y = TILE_SIZE*position.get(1);
		
		buf.drawImage(sprite.getImage(),	// the actual tile
				x,	// x position
				y,  // y position
				null);
		
		buf.setColor(Color.black);
		buf.drawRect(x, y, TILE_SIZE, TILE_SIZE);
		
		if(mouseOver) {
			buf.setColor(new Color(0,255,0,96));
			buf.fillRect(x, y, TILE_SIZE, TILE_SIZE);
			buf.setColor(Color.BLACK);
		}
		
		if(rightClicked) {
			buf.setColor(new Color(0,0,255,96));
			buf.fillRect(x, y, TILE_SIZE, TILE_SIZE);
			buf.setColor(Color.BLACK);
		}
		
		if(leftClicked) {
			buf.setColor(new Color(255,0,0,96));
			buf.fillRect(x, y, TILE_SIZE, TILE_SIZE);
			buf.setColor(Color.BLACK);
		}
		
		mouseOver = false;
	}
	
	public void mouseOver() {
		mouseOver = true;
	}
	
	public void rightClick() {
		rightClicked = (rightClicked) ? false : true;
	}
	
	public void leftClick() {
		leftClicked = (leftClicked) ? false : true;
	}
	
	public String toString() {
		return position.toString();
	}
}
